<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义过滤器——手机号加星 过滤器实例</title>
    <script src="../angular.js"></script>
</head>
<body>
<div ng-app="gg" ng-controller="ctrl">
    <table border="1" width="500px">
        <tr>
            <th>编号</th>
            <th>名字</th>
            <th>手机号</th>
        </tr>
        <tr ng-repeat="(k,v) in data" align="center">
            <td>{{v.id}}</td>
            <td>{{v.name}}</td>
            <td>{{v.phone | truncate:6}}</td>
        </tr>
    </table>
</div>

<script>
    var mod = angular.module('gg', []);

    mod.filter('truncate', function () {
        return function (phone, len) {
            len = len ? len : 3;

//            phone.substr 是字符串函数，所以phone的数据类型必须为字符串
            return phone.substr(0,8)+new String('*').repeat(len);
        }
    })
    
    mod.controller('ctrl', ['$scope', '$filter', function ($scope, $filter) {
        $scope.data = [
            {id: 1 ,name : 'gg', phone : '17701589334'},
            {id: 2 ,name : 'qc', phone : '18156590526'},
        ];

    }])
</script>
</body>
</html>